// SETUP

#include intrographics.txt
#include ladyluckbiggraphics.txt

setdatapath("data/graphics/cutscenes/inventor/");

var inventorgraphics = {
	idle: {
		animation: "inventor_idle.json",
		pack: "inventor.pck",
		loop: true
	},
	worried_idle: {
		animation: "inventor_worried_idle.json",
		pack: "inventor.pck",
		loop: true
	},
	transform: {
		animation: "inventor_transform.json",
		pack: "inventor.pck",
		speed: 2,
		loop: false
	}
}
var inventor = addsprite("inventor", 1, inventorgraphics);

// HELPER FUNCTIONS	

function signanimate(sign) {
	var s = sign.show("turn");
	//s.onComplete(function() { resume(); sign.show("loop"); });
	//pause();
	while(!s.completed) {
		// do nothing
	}
	sign.show("loop");
}

function fadein_sprite(sprite, time) {
	return;
	sprite.alpha = 0.0;
	Actuate.tween(sprite, time, { alpha: 1.0 });
	wait(time);
}

function fadeout_sprite(sprite, time) {
	return;
	Actuate.tween(sprite, time, { alpha: 0.0 });
	wait(time);
}

var fade_time = 0.4;

// ACTORS

actor("Lady Luck", screenwidthmid + 750, 550, Col.YELLOW, CENTER, BOTTOM, "chat_ladyluck", "characters/misc/charicon_ladyluck");
actor("Inventor", 2600, 600, 0xffe48d, RIGHT, TOP, "chat_inventor", "characters/inventor/charicon_inventor");
// INTRO

play("music_cutscene_cheery");

changebackground("intro_sign");

sign.y = -screenheight;
ladyluck_sign.y = -screenheight;
sign.show("loop");
ladyluck_sign.show("idle");

Actuate.tween(sign, 2, { y: 0 }).ease(Expo.easeOut);
Actuate.tween(ladyluck_sign, 2, { y: 0 }).ease(Expo.easeOut);

wait(0.5);

fadein();
play("cutscene_audience");

wait(1.5);

ladyluck_sign.show("talking", true);
speak("Lady Luck", "It's time to meet the fourth member of our little squad!");
actor("Lady Luck", screenwidthmid + 700, 550, Col.YELLOW, CENTER, BOTTOM, "chat_ladyluck", "characters/misc/charicon_ladyluck");
speak("Lady Luck", "What she lacks in attention span, she makes up for in ingenuity.", "sly");
actor("Lady Luck", screenwidthmid + 800, 550, Col.YELLOW, CENTER, BOTTOM, "chat_ladyluck", "characters/misc/charicon_ladyluck");
speak("Lady Luck", "Yes, that's right - it's time for...");
ladyluck_sign.show("idle", true);

fadeout();
while(isfading()) {
	// do nothing
}
changebackground("intro_transform");
sign.hide();
ladyluck_sign.hide();
fadein();

inventor.x = screenwidth;
var transform = inventor.show("transform");
Actuate.tween(inventor, 2, { x: 0 }).ease(Expo.easeOut);

var marker_human = false;
var marker_dice = false;
while(true) {
	if(!marker_human && transform.marker == "human") {
		marker_human = true;
		transform.paused = true;
		speak("Lady Luck", "... the Inventor!");
		play("transformintodice");
		transform.paused = false;
	} else if(!marker_dice && transform.marker == "dice") {
		marker_dice = true;
		transform.paused = true;
		actor("Inventor", screenwidthmid, screenheightmid - 300, 0xffe48d, CENTER, BOTTOM, "chat_inventor", "characters/inventor/charicon_inventor");
    speak("Inventor", "Wait, how did you do that?", "personality");
    speak("Inventor", "I’m really a dice?", "worried");
    fadeout();
	  break;
	}
}

while(isfading()) {
	// do nothing
}


inventor.scale = 0.5;
inventor.x = 2570 - ((inventor.getwidth("idle") * inventor.scale) / 2);
inventor.y = 840;
changebackground("intro_stage");
fadein();
inventor.show("idle");

ladyluck_big.x = -screenwidth;
ladyluck_big.show("idle");
Actuate.tween(ladyluck_big, 2, { x: 0 }).ease(Expo.easeOut);

play("cutscene_audience");

actor("Inventor", 2620, 780, 0xffe48d, CENTER, BOTTOM, "chat_inventor", "characters/inventor/charicon_inventor");
speak("Inventor", "Oh wow, my little legs.", "worried");
speak("Inventor", "This shouldn’t be possible!");

ladyluck_big.show("talking-sly", true);
actor("Lady Luck", screenwidthmid + 240, screenheightmid - 280, Col.YELLOW, RIGHT, BOTTOM, "chat_ladyluck", "characters/misc/charicon_ladyluck");
speak("Lady Luck", "I’m the all-powerful personification of fate,|my dear - everything’s possible.", "sly");
ladyluck_big.show("talking", true);
actor("Lady Luck", screenwidthmid + 240, screenheightmid - 240, Col.YELLOW, RIGHT, BOTTOM, "chat_ladyluck", "characters/misc/charicon_ladyluck");
speak("Lady Luck", "Now, what brought you to the Dungeons this evening?");
ladyluck_big.show("idle", true);

speak("Inventor", "Oh, we all caught the train together!");
speak("Inventor", "It was one of the new model T-132s|with the regenerative brakes!");

ladyluck_big.show("talking-confused", true);
actor("Lady Luck", screenwidthmid + 240, screenheightmid - 240, Col.YELLOW, RIGHT, BOTTOM, "chat_ladyluck", "characters/misc/charicon_ladyluck");
speak("Lady Luck", "...I see. Yes.", "confused");
speak("Lady Luck", "But what, my dear, are you hoping to WIN?", "confused");
ladyluck_big.show("idle", true);

speak("Inventor", "Complete understanding of everything in the universe!", "personality");

ladyluck_big.show("talking-sly", true);
actor("Lady Luck", screenwidthmid + 240, screenheightmid - 240, Col.YELLOW, RIGHT, BOTTOM, "chat_ladyluck", "characters/misc/charicon_ladyluck");
speak("Lady Luck", "...I can tell we’re going to have a wonderful|time in the Dungeons tonight.", "sly");
speak("Lady Luck", "So let’s get started!", "sly");
ladyluck_big.show("idle-sly", true);

play("cutscene_audience");

startgamefromcutscene();